layui.use(['form','layer'],function (){
    let form = layui.form,layer = layui.layer;
})

/**
* @author: ChengJW
* @params:
* @return:
* @date: 2021/11/11
* @description: 初始化回显新增部门部分信息
*/
$(function (){
    initDepartmentInfo();
});

/**
* @author: ChengJW
* @params:
* @return:
* @date: 2021/11/11
* @description: 放弃按钮
*/
function quitInsertDepartmentInfo() {
    //获取当前弹窗的索引，并关闭；parent 是 layui 定义的全局变量
    let index = parent.layer.getFrameIndex(window.name);
    parent.layer.close(index);
}

/**
* @author: ChengJW
* @params:
* @return:
* @date: 2021/11/11
* @description: 新增部门信息
*/
function insetDepartmentInfo() {
    //部门名称
    let dtTypeNm = $("#dtTypeNm").val().trim();
    //部门编号
    let dtTypeCode = $("#dtTypeCode").val();
    //部门所属单位名称
    let dtUpsTypeNm = $("#dtUpsTypeNm").val();
    //部门所属单位编号
    let dtUpsTypeCode = $("#dtUpsTypeCode").val();
    if (valueIsEmpty(dtTypeNm)){
        layer.msg("部门名称不能为空！",{icon:0,time:1000});
        return;
    }
    let jsonData = {
        "dtTypeNm" : dtTypeNm,
        "dtTypeCode" : dtTypeCode,
        "dtUpsTypeCode" : dtUpsTypeCode
    }
    sendAjax("/systemDefend/departmentAdmin/insertDepartment",jsonData,function (result){
        if (valueIsEqual(result.code,"00")){
            quitInsertDepartmentInfo();
        }else {
            layer.msg(result.data,{icon:5,time: 1500});
        }
    });
}

/**
* @author: ChengJW
* @params:
* @return:
* @date: 2021/11/11
* @description: 初始化返显部分部门信息
*/
function initDepartmentInfo() {
    sendAjax("/systemDefend/departmentAdmin/initDepartmentInfo",null,function (result) {
        if (valueIsEqual("00",result.code)){
            $("#dtTypeCode").val(parseInt(result.data.dtTypeCode)+1);
            $("#dtUpsTypeNm").val(result.data.dtUpsTypeNm);
            $("#dtUpsTypeCode").val(result.data.dtUpsTypeCode);
        }
    })
}